<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

class Login extends CI_Controller {
	
	function __construct() {
		parent::__construct();
	}
	
	function index(){
		$data = array(
			"title" => "Login",
			"jsarray" => array("./resources/js/login.js"),
			"extra" => ""
		);
		
		$this->load->view("header", $data);
		$this->load->view("login");
		$this->load->view("footer");
	}
	
	function check(){
		$this->load->library("session_manager",array("auth"=>false));
		$sm = $this->session_manager;
		$this->load->database();
		$this->load->model("Sys_usr_info");
		
		$email		= htmlentities($this->input->post("email",""),ENT_QUOTES);
		$password	= htmlentities($this->input->post("password",""),ENT_QUOTES);
		
		$u = $this->Sys_usr_info->get_user($email,$password); //获取用户信息
		
		if ($u){	//生成SESSION
			$_SESSION['user']['uid']		= $u->uid;
			$_SESSION['user']['email']		= $u->email;
			$_SESSION['user']['nickname']		= $u->nickname;
			$_SESSION['user']['key']		= $sm->session_key;	
						
			echo '<div class="info">成功登录！</div><script language="javascript">window.location = "'.site_url().'/home";</script>';
		} else {
			echo '<div class="error">用户名密码错误，请重新输入！</div>';
		}
		
	}
}

?>